﻿add_definitions(-DGLAPI=WINGDIAPI)
set(CONSTRUCTDESIGN_VERSION 10 CACHE STRING "ConstructDesign Software Inner Version")
set_property(CACHE CONSTRUCTDESIGN_VERSION PROPERTY STRINGS 10)
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/SoftwareVersion.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/SoftwareVersion.h"
)
set(SOURCES
	res/constructdesign.rc
	main.cpp
	mainwindow.cpp
	ribbonwindow.cpp
	aboutdialog.cpp
	DlgBase.cpp
	ExportOSGDlg.cpp
	Array2DDialog.cpp
	Scene.cpp
	JsonReader.cpp
	Intercept_QAccessible.cpp

	FitCurveTool.cpp
	GetTriangles.cpp
	EntFromEdge.cpp
	PolygonGenerator.cpp
	PolygonGeneratorHandler.cpp

	ConvexHull.cpp
	Plane.cpp

	Ent.cpp
	Ucs.cpp
	LineStrip2D.cpp
	LineStrip3D.cpp
	Arc2D.cpp
	Arc3D.cpp
	Pline2D.cpp
	Cylinder.cpp
	MultiSectionCylinder.cpp
	Spline2D.cpp
	Spline3D.cpp
	Triangles.cpp
	Surface.cpp
	Polygon.cpp

	RegisterCmds.cpp
	CmdHandler3.cpp
	PosHandler.cpp
	DistanceHandler.cpp
	SetRotateCenterHandler.cpp
	UcsHandler.cpp
	DeleteHandler.cpp
	PointHandler.cpp
	HighlightObjectUnderMouse.cpp
	Line2DHandler.cpp
	Line3DHandler.cpp
	Arc2DHandler.cpp
	Arc3DHandler.cpp
	Pline2DHandler.cpp
	CylinderHandler.cpp
	MultiSectionCylinderHandler.cpp
	PolygonWithHolesHandler.cpp
	CurveEdgePlaneSurfaceHandler.cpp
	Rectangle2DHandler.cpp
	DXFHandler.cpp
	RuledSurfaceHandler.cpp
	PointRuledSurfaceHandler.cpp
	CombineCurveHandler.cpp
	Circle2DHandler.cpp
	SweepHandler.cpp
	D2To3Handler.cpp
	Circle3DHandler.cpp
	Radius2DHandler.cpp
	Radius3DHandler.cpp

	ArrayHandler.cpp
	Array2DHandler.cpp
	Move2DHandler.cpp
	Move3DHandler.cpp
	Mirror2DHandler.cpp
	Copy2DHandler.cpp
	Copy3DHandler.cpp
	Stretch2DHandler.cpp
	Stretch3DHandler.cpp
	ExplodeHandler.cpp
	ReverseHandler.cpp
	FitCurve2DHandler.cpp
	FitCurve3DHandler.cpp
	Rotate2DHandler.cpp
	Extend2DHandler.cpp
	Trim2DHandler.cpp
	Chamfer2DHandler.cpp
	Fillet2DHandler.cpp
	Offset2DHandler.cpp
	RotateHandler.cpp
	VerticalAxisTransformHandler.cpp
	HideFaceHandler.cpp

	Operation/Op.cpp
	Operation/OpAdd.cpp
	Operation/OpDelete.cpp
	Operation/OpMove.cpp
	Operation/OpReplace.cpp
	Operation/OpReverse.cpp
	Operation/OpRotate.cpp

	CurveRevolutionHandler.cpp
	ImportModel.cpp
	ImportModelDlg.cpp
	GetLeafCount.cpp
	)
set(HEADERS
	SoftwareVersion.h.in
	ActorTable.h
	mainwindow.h
	ribbonwindow.h
	aboutdialog.h
	DlgBase.h
	ExportOSGDlg.h
	Array2DDialog.h
	Scene.h
	JsonReader.h

	FitCurveTool.h
	GetTriangles.h
	EntFromEdge.h
	PolygonGenerator.h
	PolygonGeneratorHandler.h

	Plane.h

	Ent.h
	Ucs.h
	LineStrip2D.h
	LineStrip3D.h
	Arc2D.h
	Arc3D.h
	Pline2D.h
	Cylinder.h
	MultiSectionCylinder.h
	Spline2D.h
	Spline3D.h
	Triangles.h
	Surface.h
	Polygon.h

	RegisterCmds.h
	CmdHandler3.h
	PosHandler.h
	DistanceHandler.h
	SetRotateCenterHandler.h
	UcsHandler.h
	DeleteHandler.h
	PointHandler.h
	HighlightObjectUnderMouse.h
	Line2DHandler.h
	Line3DHandler.h
	Arc2DHandler.h
	Arc3DHandler.h
	Pline2DHandler.h
	CylinderHandler.h
	MultiSectionCylinderHandler.h
	PolygonWithHolesHandler.h
	CurveEdgePlaneSurfaceHandler.h
	Rectangle2DHandler.h
	DXFHandler.h
	RuledSurfaceHandler.h
	PointRuledSurfaceHandler.h
	CombineCurveHandler.h
	SweepHandler.h
	D2To3Handler.h
	Circle3DHandler.h
	Radius2DHandler.h
	Radius3DHandler.h

	ArrayHandler.h
	Array2DHandler.h
	Move2DHandler.h
	Move3DHandler.h
	Mirror2DHandler.h
	Copy2DHandler.h
	Copy3DHandler.h
	Stretch2DHandler.h
	Stretch3DHandler.h
	ExplodeHandler.h
	ReverseHandler.h
	FitCurve2DHandler.h
	FitCurve3DHandler.h
	Rotate2DHandler.h
	Extend2DHandler.h
	Trim2DHandler.h
	Chamfer2DHandler.h
	Fillet2DHandler.h
	Circle2DHandler.h
	Offset2DHandler.h
	RotateHandler.h
	VerticalAxisTransformHandler.h
	HideFaceHandler.h

	Operation/Op.h
	Operation/OpAdd.h
	Operation/OpDelete.h
	Operation/OpMove.h
	Operation/OpReplace.h
	Operation/OpReverse.h
	Operation/OpRotate.h

	CurveRevolutionHandler.h
	ImportModelDlg.h
	)
set(DETOURS
	detours/detours.h
	detours/detver.h
	detours/creatwth.cpp
	detours/detours.cpp
	detours/disasm.cpp
	detours/disolarm.cpp
	detours/disolarm64.cpp
	detours/disolia64.cpp
	detours/disolx64.cpp
	detours/disolx86.cpp
	detours/image.cpp
	detours/modules.cpp
#	detours/uimports.cpp
)
set(QtRESOURCES
    App.qrc
	)
set(RESOURCES
	Miss_zh.ts
	res/ribbon-zh.xml
    ${QtRESOURCES}
	)
qt5_add_resources(RES_SOURCES ${QtRESOURCES})

add_compile_definitions(
	# _CRT_SECURE_NO_DEPRECATE
	# _WIN32
	# _WINDOWS
	# _CRT_NOFORCE_MANIFEST
	# _STL_NOFORCE_MANIFEST
	# _CRTDBG_MAP_ALLOC
	)

if(MSVC)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif(MSVC)
set(project App)
add_executable(${project} WIN32 ${SOURCES} ${DETOURS} ${HEADERS} ${RESOURCES} ${RES_SOURCES})
set_target_properties(${project} PROPERTIES OUTPUT_NAME ConstructDesign)
# add d suffix for Debug configuration
set_target_properties(${project} PROPERTIES DEBUG_POSTFIX d)
target_link_libraries(${project} Qt5::Widgets Log Registry RibbonXML QtCommand ShxParser QtOSG Utility Qt2D QtMath OcctUtil DXF Qt2Dxf ${OPENSCENEGRAPH_LIBRARIES})
target_include_directories(${project} PRIVATE $<BUILD_INTERFACE:${OPENSCENEGRAPH_INCLUDE_DIRS}>)
target_include_directories(${project} PRIVATE $<BUILD_INTERFACE:${QtRibbon_DIR}/include>)
find_library(QtRibbonDebug qtnribbond4 PATHS ${QtRibbon_DIR}/bin)
find_library(QtRibbonRelease qtnribbon4 PATHS ${QtRibbon_DIR}/bin)
target_link_libraries(${project} debug ${QtRibbonDebug} optimized ${QtRibbonRelease})
target_include_directories(${project} PRIVATE ${Third_DIR}/OpenGLCore)
#target_link_directories(${project} PRIVATE "${Third_VS_DIR}/OCCT/win64/vc14/$<IF:$<CONFIG:Debug>,libd,lib>")
set (OpenCASCADE_FIND_COMPONENTS FoundationClasses;ModelingData;ModelingAlgorithms)
include("${Third_VS_DIR}/OCCT/cmake/OpenCASCADEConfig.cmake")
target_include_directories(${project} PRIVATE $<BUILD_INTERFACE:${OpenCASCADE_INCLUDE_DIR}>)
target_include_directories(${project} PRIVATE ${Third_VS_DIR}/Deping/include/BrepJson)
target_link_libraries(${project} debug ${Third_VS_DIR}/Deping/lib/BrepJsond.lib optimized ${Third_VS_DIR}/Deping/lib/BrepJson.lib)
target_link_libraries(${project} TKernel TKMath TKG2d TKG3d TKGeomBase TKBRep TKGeomAlgo TKTopAlgo TKPrim TKBO TKShHealing TKBool TKHLR TKFillet TKOffset TKFeat TKMesh TKXMesh)

# This command will only execute when the target itself is built. If the target is already built, the command will not execute.
# So I use another target to ensure that whenever CloudPictureViewer.plugins.json is changed, copy it to application directory.
# add_custom_command(TARGET ${project}
# 	POST_BUILD
# 	COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/CloudPictureViewer.plugins.json" "$<TARGET_FILE_DIR:${project}>")

set(MISS_TS_FILES Miss_zh.ts)
qt5_add_translation(MISS_QM_FILES ${MISS_TS_FILES})

add_custom_target(App_CopyFiles ALL
	COMMAND ${CMAKE_COMMAND} -E copy ${MISS_QM_FILES} "$<TARGET_FILE_DIR:${project}>"
	COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/ACAD" "$<TARGET_FILE_DIR:${project}>/ACAD"
	COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/Cursor" "$<TARGET_FILE_DIR:${project}>/Cursor"
	COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:App>" "${RebarDesignBuild_DIR}/$<$<CONFIG:Debug>:调试>$<$<CONFIG:Release>:Release>"
	DEPENDS ${MISS_QM_FILES}
            )

source_group("Resource Files" FILES ${RESOURCES} res/ribbon-zh.xml)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Header Files" FILES ${HEADERS})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source Files" FILES ${SOURCES})
source_group("Detours Files" FILES ${DETOURS})

# 解决在Visual Studio调试时找不到dll的问题
message(STATUS OpenCASCADE_BINARY_DIR=${OpenCASCADE_BINARY_DIR})
set(ENV_PATH_DEBUG
${QTDIR}/bin
${Third_VS_DIR}/zlib/bin
${Third_VS_DIR}/Boost/bin
${Third_VS_DIR}/OpenSceneGraph/bin
${Third_VS_DIR}/QtitanRibbon/bin
${Third_VS_DIR}/Deping/bin
${OpenCASCADE_BINARY_DIR}d
)
set(ENV_PATH_RELEASE
${QTDIR}/bin
${Third_VS_DIR}/zlib/bin
${Third_VS_DIR}/Boost/bin
${Third_VS_DIR}/OpenSceneGraph/bin
${Third_VS_DIR}/QtitanRibbon/bin
${Third_VS_DIR}/Deping/bin
${OpenCASCADE_BINARY_DIR}
)
string(REPLACE "/" "\\" ENV_PATH_DEBUG "${ENV_PATH_DEBUG}")
string(REPLACE "/" "\\" ENV_PATH_RELEASE "${ENV_PATH_RELEASE}")
# 必须使用%3b代替分号，否则分号传递不到template.vcxproj.user
string(REPLACE ";" "%3b" ENV_PATH_DEBUG "${ENV_PATH_DEBUG}")
string(REPLACE ";" "%3b" ENV_PATH_RELEASE "${ENV_PATH_RELEASE}")
configure_file(template.vcxproj.user ${project}.vcxproj.user)
